import numpy as np
import matplotlib.pyplot as plt

x = np.linspace(-5,5,50)
y = []
for item in x:
    if item < 0:
        y.append(0)
    else:
        y.append(item)

# 列表转化为numpy对象
y = np.array(y,dtype=float)

plt.plot(x,y,'r-')
plt.show()